package com.qf.ks.controller;

import com.github.pagehelper.PageInfo;
import com.qf.ks.dto.R;
import com.qf.ks.pojo.Books;
import com.qf.ks.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.RequestWrapper;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/book")
public class BooksController {
    private BooksService booksService;
    @Autowired
    public void setBooksService(BooksService booksService) {
        this.booksService = booksService;
    }
    @PostMapping("/newbook")
    public R AddBooks(@RequestBody Books books){
        booksService.AddBooks(books);
        return R.setOk(books);
    }
    @GetMapping("/books/{name}/{pageNum}/{pageSize}")
    public R getAllBookByBookNameOrByAuthorName(@PathVariable String name,@PathVariable int pageNum,@PathVariable int pageSize) throws UnsupportedEncodingException {

        PageInfo<Books> pageInfo = booksService.getAllBookByBookNameOrByAuthorName(name, pageNum, pageSize);

        return R.setOk(pageInfo);

    }
}
